package pers.baiban.sqltoword.handler.impl;

import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import pers.baiban.sqltoword.handler.AbstractTableProcessor;
import pers.baiban.sqltoword.handler.TableProcessor;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 表格内所有单元格处理器 (字号)
 *
 * @author 强子初
 * @since 2023/11/29
 */
@Component
@Order(5)
public class TableAllCellFontSizeProcessor extends AbstractTableProcessor implements TableProcessor {

    @Override
    public void doHandler() {
        if (needUpdate(param.getTableCellFontSize())) {
            getRun().forEach(it -> it.setFontSize(param.getTableCellFontSize()));
        }
    }

    /**
     * 获取表格单元格文本样式
     */
    private List<XWPFRun> getRun() {
        return cells.stream()
                .map(cell -> cell.getParagraphArray(0))
                .map(paragraph -> paragraph.getRuns().get(0))
                .collect(Collectors.toList());
    }
}